<!--
 * @Author: 13474815223 nm.baoxuhui@aisino.com
 * @Date: 2023-11-16 14:15:27
 * @LastEditors: ‘baobao’ baoxuhui@nmgheli.com
 * @LastEditTime: 2025-04-02 17:08:52
 * @FilePath: \tjbuildingprojectmanagesysweb\src\components\Pagination\list.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <!--  -->
  <div :class="{'hidden':hidden}" class="pagination-container">
    <el-pagination
      :class="!paginationSizesFlag?'paginationSizesNone':''"
      :background="background"
      :current-page.sync="currentPage"
      :page-size.sync="pageSize"
      :layout="layout"
      :page-sizes="pageSizes"
      :total="total"
      v-bind="$attrs"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
// import { scrollTo } from '@/utils/commonUtils/scroll-to'

export default {
  name: 'Pagination',
  inject: ['listQueryParams'],
  props: {
    objName:{
      type: String,
      default() {
        return 'getList';
      }
    },
    total: {
      required: true,
      type: Number
    },
    page: {
      type: Number,
      default: 1
    },
    limit: {
      type: Number,
      default: 10
    },
    pageSizes: {
      type: Array,
      default() {
        return [this.listQueryParams.queryData.queryParams.pageSize * 1, this.listQueryParams.queryData.queryParams.pageSize * 2, this.listQueryParams.queryData.queryParams.pageSize * 3, this.listQueryParams.queryData.queryParams.pageSize * 5]
      }
    },
    layout: {
      type: String,
      default: 'total, sizes, prev, pager, next, jumper'
    },
    background: {
      type: Boolean,
      default: true
    },
    autoScroll: {
      type: Boolean,
      default: true
    },
    hidden: {
      type: Boolean,
      default: false
    },
    paginationSizesFlag: {
      type: Boolean,
      default: true
    }
  },
  computed: {
    currentPage: {
      get() {
        return this.page
      },
      set(val) {
        this.$emit('update:page', val)
      }
    },
    pageSize: {
      get() {
        return this.limit
      },
      set(val) {
        this.$emit('update:limit', val)
      }
    }
  },
  methods: {
    handleSizeChange(val) {
      if (this.sentencedEmpty(this.listQueryParams.$refs['advancedQueryShrinkComponent'])) {
        this.listQueryParams.$refs['advancedQueryShrinkComponent'].handleQueryFun({ pageNum: this.currentPage, pageSize: val })
      } else {
        if (this.objName == 'getList') {
          this.listQueryParams.getList({ pageNum: this.currentPage, pageSize: val })
        } else if (this.objName == 'dialogGetList'){
          this.listQueryParams.dialogGetList({ pageNum: this.currentPage, pageSize: val })
        } else {
          this.$emit('pagination',{ pageNum: this.currentPage, pageSize: val })
        }
      }
    },
    handleCurrentChange(val) {
      if (this.sentencedEmpty(this.listQueryParams.$refs['advancedQueryShrinkComponent'])) {
        this.listQueryParams.$refs['advancedQueryShrinkComponent'].handleQueryFun({ pageNum: val, pageSize: this.pageSize })
      } else {
        if (this.objName == 'getList') {
          this.listQueryParams.getList({ pageNum: val, pageSize: this.pageSize })
        } else if (this.objName == 'dialogGetList '){
          this.listQueryParams.dialogGetList({ pageNum: val, pageSize: this.pageSize })
        } else {
          this.$emit('pagination',{ pageNum: val, pageSize: this.pageSize })
        }
      }
    }
  }
}
</script>

